#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021, Jeff McBride
# Copyright (c) 2022, Christopher Durand
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:samv71-xplained-ultra"
    module.description = "Microchip SAMV71 Xplained Ultra"

def prepare(module, options):
    if not options[":target"].partname == "samv71q21b-aab":
        return False

    module.depends(":debug",
                   ":platform:can:1",
                   ":platform:clockgen",
                   ":platform:core",
                   ":platform:gpio",
                   ":platform:i2c:0",
                   ":platform:usart:1")  # , ":platform:usb")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": True,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('board.hpp')
    env.copy(repopath("tools/openocd/modm/atmel_samv71_xplained_ultra.cfg"), "atmel_samv71_xplained_ultra.cfg")
    env.collect(":build:openocd.source", "modm/src/modm/board/atmel_samv71_xplained_ultra.cfg")
